package com.cgw.game.ui;

import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.RecyclerView;

import com.cgw.game.R;
import com.cgw.game.entity.SleepStatusData;
import com.cgw.game.view.CustomCombinedChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.CombinedData;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class DoubleLineBar2Activity extends AppCompatActivity {
    private CustomCombinedChart chart;
    private String sleepJson="[{\"duration\":470,\"endTime\":1577728199,\"startTime\":1577700000,\"status\":\"LSSleepStatusSober\"},{\"duration\":30,\"endTime\":1577729999,\"startTime\":1577728199,\"status\":\"LSSleepStatusLight\"},{\"duration\":15,\"endTime\":1577730899,\"startTime\":1577729999,\"status\":\"LSSleepStatusDeep\"},{\"duration\":65,\"endTime\":1577734799,\"startTime\":1577730899,\"status\":\"LSSleepStatusLight\"},{\"duration\":10,\"endTime\":1577735399,\"startTime\":1577734799,\"status\":\"LSSleepStatusDeep\"},{\"duration\":40,\"endTime\":1577737799,\"startTime\":1577735399,\"status\":\"LSSleepStatusLight\"},{\"duration\":20,\"endTime\":1577738999,\"startTime\":1577737799,\"status\":\"LSSleepStatusDeep\"},{\"duration\":125,\"endTime\":1577746499,\"startTime\":1577738999,\"status\":\"LSSleepStatusLight\"},{\"duration\":5,\"endTime\":1577746799,\"startTime\":1577746499,\"status\":\"LSSleepStatusDeep\"},{\"duration\":20,\"endTime\":1577747999,\"startTime\":1577746799,\"status\":\"LSSleepStatusLight\"},{\"duration\":360,\"endTime\":1577769599,\"startTime\":1577747999,\"status\":\"LSSleepStatusSober\"},{\"duration\":40,\"startTime\":1577769599,\"endTime\":1577771999,\"status\":\"LSSleepStatusNap\"}]";
    private String heartJosn ="[64,68,73,71,73,73,71,70,69,70,66,70,67,68,75,85,113,138,137,130,129,128,129,128,78,71,77,115,97,89,90,87,82,79,77,72,78,79,88,74,76,80,84,89,90,85,82,80,78,74,73,74,73,74,70,72,73,68,67,69,72,71,76,71,70,70,65,64,68,65,67,70,72,66,70,75,74,66,68,74,69,68,68,70,63,69,71,67,66,69,69,75,78,74,65,61,61,58,55,52,52,49,49,49,52,52,52,53,56,55,58,58,55,52,52,51,50,50,51,49,49,49,49,49,48,48,50,51,48,48,48,52,54,52,52,52,52,54,53,49,49,46,46,46,46,47,43,40,38,49,49,49,49,49,48,49,49,51,53,54,52,65,64,65,112,137,134,140,158,142,133,135,92,80,67,88,89,78,75,73,83,78,79,79,78,80,74,77,74,74,74,77,82,80,84,88,81,78,75,76,76,72,75,75,75,77,76,75,74,74,73,79,89,88,68,65,72,83,87,90,107,90,85,80,80,81,78,75,78,82,82,79,71,68,65,73,79,86,81,78,77,78,80,78,78,78,77,76,77,73,77,76,78,75,81,86,80,82,81,84,80,77,72,80,82,79,78,77,74,73,81,78,78,76,75,75,74,72,76,83,81,84,78,76,76,74,85,91]";
    private String sleePrimaryJosn ="[99,99,68,99,99,99,91,89,50,99,40,99,99,70,99,99,88,50,49,45,70,70,99,99,99,53,54,66,67,89,99,99,83,82,94,99,54,99,44,74,82,99,99,71,86,99,72,99,99,97,50,35,58,50,99,67,82,99,99,99,99,99,70,81,67,86,66,82,70,54,58,79,78,70,50,66,99,99,90,99,99,99,99,99,99,99,99,35,56,66,76,84,61,54,97,33,86,59,27,33,16,7,0,10,0,0,47,0,20,32,50,43,0,35,29,13,7,27,39,27,12,0,22,19,14,0,0,0,1,0,9,21,31,28,32,38,0,33,12,0,21,43,35,38,10,16,0,29,26,16,20,20,33,26,17,24,21,15,7,0,13,19,0,13,7,15,27,33,5,7,31,24,7,99,99,99,99,99,56,80,99,60,99,66,69,70,72,69,80,67,99,80,93,75,51,86,99,70,67,99,70,99,77,99,87,99,99,50,45,40,84,30,40,99,89,58,86,99,50,50,49,39,50,56,70,99,99,99,99,99,68,99,99,99,88,25,0,0,6,13,16,0,16,15,99,99,99,99,99,99,83,99,99,99,56,40,98,46,99,87,56,99,71,50,99,45,96,99,44,99,99,99,97,30,39,56,82,59,99,99,99,70,50,99,99,99,96,77]";
    private String dataJson = "{\"周日\":{\"sleep\":[{\"duration\":1440,\"startTime\":1575712800,\"endTime\":1575799200,\"status\":\"LSSleepStatusWorn\"}],\"motion\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"heart\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"周六\":{\"sleep\":[{\"duration\":1440,\"startTime\":1575626400,\"endTime\":1575712800,\"status\":\"LSSleepStatusWorn\"}],\"motion\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"heart\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"周五\":{\"sleep\":[{\"duration\":1440,\"startTime\":1575540000,\"endTime\":1575626400,\"status\":\"LSSleepStatusWorn\"}],\"motion\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"heart\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"周四\":{\"sleep\":[{\"duration\":180,\"startTime\":1575453600,\"endTime\":1575464400,\"status\":\"LSSleepStatusSober\"},{\"duration\":120,\"startTime\":1575464400,\"endTime\":1575471600,\"status\":\"LSSleepStatusWorn\"},{\"duration\":9,\"startTime\":1575471600,\"endTime\":1575472199,\"status\":\"LSSleepStatusSober\"},{\"duration\":309,\"startTime\":1575453600,\"endTime\":1575472199,\"status\":\"LSSleepStatusSober\"},{\"duration\":45,\"startTime\":1575472199,\"endTime\":1575474899,\"status\":\"LSSleepStatusLight\"},{\"duration\":5,\"startTime\":1575474899,\"endTime\":1575475199,\"status\":\"LSSleepStatusAwake\"},{\"duration\":65,\"startTime\":1575475199,\"endTime\":1575479099,\"status\":\"LSSleepStatusLight\"},{\"duration\":10,\"startTime\":1575479099,\"endTime\":1575479699,\"status\":\"LSSleepStatusDeep\"},{\"duration\":105,\"startTime\":1575479699,\"endTime\":1575485999,\"status\":\"LSSleepStatusLight\"},{\"duration\":20,\"startTime\":1575485999,\"endTime\":1575487199,\"status\":\"LSSleepStatusDeep\"},{\"duration\":60,\"startTime\":1575487199,\"endTime\":1575490799,\"status\":\"LSSleepStatusLight\"},{\"duration\":25,\"startTime\":1575490799,\"endTime\":1575492299,\"status\":\"LSSleepStatusDeep\"},{\"duration\":115,\"startTime\":1575492299,\"endTime\":1575499199,\"status\":\"LSSleepStatusLight\"},{\"duration\":140,\"startTime\":1575499199,\"endTime\":1575507600,\"status\":\"LSSleepStatusSober\"},{\"duration\":540,\"startTime\":1575507600,\"endTime\":1575540000,\"status\":\"LSSleepStatusWorn\"}],\"motion\":[72,103,921,0,0,19,0,0,0,0,0,0,1291,1731,772,0,0,0,0,0,0,0,0,0],\"heart\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,65,63,63,62,61,60,63,63,65,63,60,64,64,64,63,62,61,59,63,63,58,56,56,59,60,62,65,65,62,59,60,57,56,56,53,59,55,59,62,64,64,55,54,55,59,57,60,62,61,60,61,59,58,58,59,58,57,57,60,59,58,60,58,58,58,62,62,62,57,58,59,61,59,60,59,59,58,59,60,63,73,116,120,116,124,85,81,89,84,82,81,84,94,94,94,82,90,95,94,94,94,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},\"周三\":{\"sleep\":[{\"duration\":299,\"startTime\":1575367200,\"endTime\":1575385199,\"status\":\"LSSleepStatusSober\"},{\"duration\":299,\"startTime\":1575367200,\"endTime\":1575385199,\"status\":\"LSSleepStatusSober\"},{\"duration\":50,\"startTime\":1575385199,\"endTime\":1575388199,\"status\":\"LSSleepStatusLight\"},{\"duration\":20,\"startTime\":1575388199,\"endTime\":1575389399,\"status\":\"LSSleepStatusDeep\"},{\"duration\":30,\"startTime\":1575389399,\"endTime\":1575391199,\"status\":\"LSSleepStatusLight\"},{\"duration\":15,\"startTime\":1575391199,\"endTime\":1575392099,\"status\":\"LSSleepStatusDeep\"},{\"duration\":50,\"startTime\":1575392099,\"endTime\":1575395099,\"status\":\"LSSleepStatusLight\"},{\"duration\":5,\"startTime\":1575395099,\"endTime\":1575395399,\"status\":\"LSSleepStatusAwake\"},{\"duration\":30,\"startTime\":1575395399,\"endTime\":1575397199,\"status\":\"LSSleepStatusLight\"},{\"duration\":5,\"startTime\":1575397199,\"endTime\":1575397499,\"status\":\"LSSleepStatusDeep\"},{\"duration\":35,\"startTime\":1575397499,\"endTime\":1575399599,\"status\":\"LSSleepStatusLight\"},{\"duration\":20,\"startTime\":1575399599,\"endTime\":1575400799,\"status\":\"LSSleepStatusDeep\"},{\"duration\":30,\"startTime\":1575400799,\"endTime\":1575402599,\"status\":\"LSSleepStatusLight\"},{\"duration\":10,\"startTime\":1575402599,\"endTime\":1575403199,\"status\":\"LSSleepStatusDeep\"},{\"duration\":20,\"startTime\":1575403199,\"endTime\":1575404399,\"status\":\"LSSleepStatusLight\"},{\"duration\":15,\"startTime\":1575404399,\"endTime\":1575405299,\"status\":\"LSSleepStatusDeep\"},{\"duration\":35,\"startTime\":1575405299,\"endTime\":1575407399,\"status\":\"LSSleepStatusLight\"},{\"duration\":25,\"startTime\":1575407399,\"endTime\":1575408899,\"status\":\"LSSleepStatusDeep\"},{\"duration\":40,\"startTime\":1575408899,\"endTime\":1575411299,\"status\":\"LSSleepStatusLight\"},{\"duration\":705,\"startTime\":1575411299,\"endTime\":1575453600,\"status\":\"LSSleepStatusSober\"}],\"motion\":[205,370,584,0,18,35,0,13,0,0,0,0,1125,2010,991,32,23,1204,204,1309,223,371,187,301],\"heart\":[102,110,80,78,76,76,80,96,96,74,73,71,71,76,76,95,80,82,91,74,76,78,98,93,86,87,86,87,96,95,111,101,92,108,84,89,91,111,120,124,127,120,126,124,130,127,126,125,118,118,120,123,123,126,116,119,131,137,131,137,133,123,120,116,68,65,63,62,63,62,63,65,59,59,59,65,67,68,70,67,65,63,61,61,60,61,63,59,58,59,58,57,55,56,57,64,63,62,62,65,65,66,65,63,59,58,62,59,60,60,59,59,60,57,56,54,52,53,53,54,55,56,60,60,59,59,60,59,62,61,62,63,61,57,57,58,59,59,60,60,59,59,56,59,66,62,60,66,64,67,84,86,102,100,95,78,82,75,70,76,78,121,126,157,151,100,84,89,89,100,103,101,88,78,79,89,94,82,80,82,93,96,87,72,72,89,65,74,81,79,75,76,76,80,77,74,72,74,77,73,74,72,78,84,82,84,90,87,88,74,73,74,70,71,72,106,110,82,71,73,76,77,78,76,74,82,95,82,81,88,95,104,110,105,93,94,84,87,87,74,62,76,81,77,80,84,81,92,81,79,78,81,74,76,78,79,79,75,88,91,84,101,97,101,106,108,93,79,85,85,85,89,81,92,72,73,76,77,79,86,0,90,96,99,86,92,93,104]},\"周二\":{\"sleep\":[{\"duration\":165,\"startTime\":1575280800,\"endTime\":1575290700,\"status\":\"LSSleepStatusSober\"},{\"duration\":130,\"startTime\":1575290700,\"endTime\":1575298500,\"status\":\"LSSleepStatusWorn\"},{\"duration\":19,\"startTime\":1575298500,\"endTime\":1575299699,\"status\":\"LSSleepStatusSober\"},{\"duration\":314,\"startTime\":1575280800,\"endTime\":1575299699,\"status\":\"LSSleepStatusSober\"},{\"duration\":140,\"startTime\":1575299699,\"endTime\":1575308099,\"status\":\"LSSleepStatusLight\"},{\"duration\":5,\"startTime\":1575308099,\"endTime\":1575308399,\"status\":\"LSSleepStatusDeep\"},{\"duration\":35,\"startTime\":1575308399,\"endTime\":1575310499,\"status\":\"LSSleepStatusLight\"},{\"duration\":5,\"startTime\":1575310499,\"endTime\":1575310799,\"status\":\"LSSleepStatusAwake\"},{\"duration\":85,\"startTime\":1575310799,\"endTime\":1575315899,\"status\":\"LSSleepStatusLight\"},{\"duration\":25,\"startTime\":1575315899,\"endTime\":1575317399,\"status\":\"LSSleepStatusDeep\"},{\"duration\":25,\"startTime\":1575317399,\"endTime\":1575318899,\"status\":\"LSSleepStatusLight\"},{\"duration\":15,\"startTime\":1575318899,\"endTime\":1575319799,\"status\":\"LSSleepStatusDeep\"},{\"duration\":60,\"startTime\":1575319799,\"endTime\":1575323399,\"status\":\"LSSleepStatusLight\"},{\"duration\":35,\"startTime\":1575323399,\"endTime\":1575325499,\"status\":\"LSSleepStatusDeep\"},{\"duration\":695,\"startTime\":1575325499,\"endTime\":1575367200,\"status\":\"LSSleepStatusSober\"}],\"motion\":[19,324,0,0,0,0,0,19,0,0,0,24,641,2380,145,114,117,1323,1116,16,219,85,337,43],\"heart\":[79,81,81,85,93,78,74,76,79,82,77,77,88,95,101,93,94,100,107,77,79,89,91,87,85,89,98,103,111,133,127,114,106,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,74,73,72,70,67,73,70,69,63,62,60,60,59,60,59,64,62,59,58,60,58,57,57,56,56,57,57,59,59,60,59,57,57,56,55,56,56,56,58,57,56,64,60,58,58,60,60,60,65,62,59,61,61,65,65,64,62,62,62,60,60,60,60,60,59,59,58,57,57,57,57,57,60,62,65,63,62,61,61,61,63,55,55,56,56,55,55,55,56,56,65,104,95,109,109,99,116,114,98,92,73,74,82,93,164,145,101,96,88,96,103,80,85,84,79,80,80,85,82,76,73,76,111,78,81,84,92,80,76,83,80,82,79,79,76,77,88,75,79,80,75,73,82,76,75,80,88,86,76,80,78,82,82,82,92,90,88,107,120,123,109,98,86,84,89,86,80,75,72,79,83,86,93,83,82,78,77,82,83,80,80,82,87,90,96,86,86,80,81,80,93,85,90,92,83,86,85,81,87,82,98,114,110,83,77,78,80,80,99,97,97,92,91,81,73,77,94,89,95,101,84,86,93,107,103,104,88,83,77]},\"周一\":{\"sleep\":[{\"duration\":145,\"startTime\":1575194400,\"endTime\":1575203100,\"status\":\"LSSleepStatusSober\"},{\"duration\":160,\"startTime\":1575203100,\"endTime\":1575212700,\"status\":\"LSSleepStatusWorn\"},{\"duration\":55,\"startTime\":1575212700,\"endTime\":1575216000,\"status\":\"LSSleepStatusSober\"},{\"duration\":540,\"startTime\":1575216000,\"endTime\":1575248400,\"status\":\"LSSleepStatusWorn\"},{\"duration\":219,\"startTime\":1575248400,\"endTime\":1575261599,\"status\":\"LSSleepStatusSober\"},{\"duration\":1119,\"startTime\":1575194400,\"endTime\":1575261599,\"status\":\"LSSleepStatusSober\"},{\"duration\":45,\"startTime\":1575261599,\"endTime\":1575264299,\"status\":\"LSSleepStatusNap\"},{\"duration\":275,\"startTime\":1575264299,\"endTime\":1575280800,\"status\":\"LSSleepStatusSober\"}],\"motion\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3613,91,1195,1123,0,37,109,30,95],\"heart\":[84,74,81,83,73,72,73,71,70,75,75,80,74,74,72,71,71,73,77,85,112,98,87,89,96,95,94,88,92,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,85,72,67,64,62,63,63,63,63,61,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,77,76,77,74,74,79,83,81,79,77,81,84,93,94,79,82,76,77,74,79,74,76,78,79,77,83,79,75,72,76,82,77,79,58,47,51,65,108,107,95,90,93,95,88,85,75,71,70,69,66,66,67,66,71,89,88,81,77,80,83,88,83,95,80,86,82,90,84,80,80,78,76,81,83,80,83,82,84,85,78,75,78,82,79,88,93,90,83,83,80,85,90,76,78,79,77,85,83,88,74,80,79,73,75,84,68,78]}}";
    private RecyclerView recycler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_double_line_bar2);

        Toolbar toolbar = findViewById(R.id.toolbar);
        toolbar.setTitle(getIntent().getStringExtra("title"));
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);//左侧添加一个默认的返回图标
        getSupportActionBar().setHomeButtonEnabled(true); //设置返回键可用
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();//返回
            }
        });
        chart = findViewById(R.id.chart);
        initBarLineChart();
        setDate();
       /* recycler = findViewById(R.id.recycler);
        recycler.setLayoutManager(new LinearLayoutManager(this));
        ArrayList<DoubleLineBar2Entity> data = new ArrayList<>();
        LinkedHashMap<String,DoubleLineBar2Entity> dayNightSleep = new Gson().fromJson(dataJson,new TypeToken<LinkedHashMap<String,DoubleLineBar2Entity>>() {}.getType());
        for(Map.Entry<String, DoubleLineBar2Entity> entry : dayNightSleep.entrySet()){
            data.add(entry.getValue());
        }
        recycler.setAdapter(new DoubleLineBar2Adapter(data));*/
    }

    private void setDate() {
        chart.clear();
        CombinedData data = new CombinedData();

        LineData lineData = new LineData(getHeartEntry());
        data.setData(lineData);

        BarData barData = new BarData();
        barData.addDataSet(getBarEntry2());// 添加一组柱形图，如果有多组柱形图数据，则可以多次addDataSet来设置
        barData.addDataSet(getBarEntry());// 添加一组柱形图，如果有多组柱形图数据，则可以多次addDataSet来设置
        barData.setBarWidth(1f);
        data.setData(barData);


        chart.setData(data);
        chart.notifyDataSetChanged();
        chart.invalidate();

    }

    private LineDataSet getHeartEntry(){
        List<Float> heart = new Gson().fromJson(heartJosn,new TypeToken<List<Float>>() {}.getType());
        List<Entry> values = new ArrayList<>();
        for (int i = 0; i < heart.size(); i++) {
            values.add(new Entry(i,heart.get(i)));

        }
        LineDataSet lineDataSet;
        lineDataSet = new LineDataSet(values, "心率");
        lineDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
        lineDataSet.setColor(getResources().getColor(R.color.red));
        lineDataSet.setCircleColor(getResources().getColor(R.color.red));
        lineDataSet.setDrawHorizontalHighlightIndicator(false);
        lineDataSet.setHighLightColor(getResources().getColor(R.color.red));
        lineDataSet.enableDashedHighlightLine(10, 10, 0);
        lineDataSet.setFillDrawable(getResources().getDrawable(R.drawable.line_chart_bg));
        lineDataSet.setFillAlpha(100);
        lineDataSet.setDrawFilled(false);
        lineDataSet.setHighlightLineWidth(1f);
        lineDataSet.setLineWidth(1f);
        lineDataSet.setCircleRadius(3f);
        lineDataSet.setHighlightEnabled(false);
        lineDataSet.setDrawCircleHole(false);
        lineDataSet.setDrawCircles(false);
        lineDataSet.setDrawValues(false);
        return lineDataSet;
    }


    private BarDataSet getBarEntry2(){
        List<Float> heart = new Gson().fromJson(sleePrimaryJosn,new TypeToken<List<Float>>() {}.getType());
        List<BarEntry> values = new ArrayList<>();
        for (int i = 0; i < heart.size(); i++) {
            if(heart.get(i) >=99){
                values.add(new BarEntry(i,new Random().nextInt(40)+60));
            }else{
                values.add(new BarEntry(i,heart.get(i)));
            }

        }
        BarDataSet barDataSet = new BarDataSet(values, "睡眠原始"); // 新建一组柱形图，"LAR"为本组柱形图的Label
        barDataSet.setColor(getResources().getColor(R.color.black)); // 设置柱形图颜色
        //不显示值
        barDataSet.setDrawValues(false);
        barDataSet.setAxisDependency(YAxis.AxisDependency.RIGHT);
        barDataSet.setBarBorderWidth(1f);
        barDataSet.setHighlightEnabled(false);
        return barDataSet;
    }


    private BarDataSet getBarEntry(){
        List<BarEntry> values = new ArrayList<>();
        ArrayList<SleepStatusData> sleepStatus = new Gson().fromJson(sleepJson,new TypeToken<List<SleepStatusData>>() {}.getType());
        int j = 0;
        for (int i = 0; i < sleepStatus.size(); i++) {
            int duration = sleepStatus.get(i).getDuration();
            switch (sleepStatus.get(i).getStatus()) {
                case "LSSleepStatusAwake":
                    for (int i1 = 0; i1 < duration / 5; i1++) {
                        values.add((new BarEntry(j, 240, sleepStatus.get(i))));
                        j++;
                    }
                    break;
                case "LSSleepStatusLight":
                    for (int i1 = 0; i1 < duration / 5; i1++) {
                        values.add((new BarEntry(j, 230, sleepStatus.get(i))));
                        j++;
                    }
                    break;
                case "LSSleepStatusDeep":
                    for (int i1 = 0; i1 < duration / 5; i1++) {
                        values.add((new BarEntry(j, 225, sleepStatus.get(i))));
                        j++;
                    }
                    break;
                case "LSSleepStatusSober":
                    for (int i1 = 0; i1 < duration / 5; i1++) {
                        values.add((new BarEntry(j, 0, sleepStatus.get(i))));
                        j++;
                    }
                    break;
                case "LSSleepStatusNap":
                    for (int i1 = 0; i1 < duration / 5; i1++) {
                        values.add((new BarEntry(j, 250, sleepStatus.get(i))));
                        j++;
                    }
                    break;
                case "LSSleepStatusWorn":
                    for (int i1 = 0; i1 < duration / 5; i1++) {
                        values.add((new BarEntry(j, 220, sleepStatus.get(i))));
                        j++;
                    }
                    break;
            }
        }
        BarDataSet barDataSet = new BarDataSet(values, "睡眠"); // 新建一组柱形图，"LAR"为本组柱形图的Label
        barDataSet.setColor(getResources().getColor(R.color.blue_21)); // 设置柱形图颜色
        //不显示值
        barDataSet.setDrawValues(false);
        barDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
        barDataSet.setBarBorderWidth(1f);
        barDataSet.setHighlightEnabled(true);
        return barDataSet;
    }
    private void initBarLineChart() {
        chart.setTouchEnabled(true);
        chart.setPinchZoom(false);
        chart.setScaleYEnabled(false);
        chart.setDragEnabled(true);
        chart.setDoubleTapToZoomEnabled(false);
//        chart.getViewPortHandler().setMaximumScaleX(5.0f);
        //取消说明
        chart.getLegend().setEnabled(false);
        chart.getDescription().setEnabled(false);
        chart.setNoDataText("暂无数据");


        YAxis leftAxis = chart.getAxisLeft();
        leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
        leftAxis.setTextSize(10f);
        leftAxis.setTextColor(Color.parseColor("#91a2a3"));
        leftAxis.setGridColor(Color.parseColor("#e3edf2"));
        leftAxis.setDrawAxisLine(false);
        leftAxis.setAxisMinimum(0f);
        leftAxis.setAxisMaximum(200f);
        leftAxis.setLabelCount(5, true);
        leftAxis.setEnabled(false);



        YAxis rightAxis = chart.getAxisRight();
        rightAxis.setTextColor(Color.RED);
        rightAxis.setAxisMinimum(0);
        rightAxis.setAxisMaximum(250);
        rightAxis.setDrawGridLines(false);
        rightAxis.setGranularityEnabled(false);
        rightAxis.setEnabled(false);

        //横向轴线设置
        XAxis xAxis = chart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setTextSize(12f);
        xAxis.setTextColor(Color.parseColor("#91a2a3"));
        xAxis.setDrawGridLines(false);
        xAxis.setAxisMinimum(0f);
        xAxis.setGranularityEnabled(true);
        xAxis.setLabelCount(5, false);
        // 转换要显示的标签文本，value值默认是int从0开始
        xAxis.setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                return famatTime((int) value);
            }
        });
        xAxis.setAxisLineColor(Color.parseColor("#e3edf2"));
        //设置为虚线
        xAxis.setDrawAxisLine(true);
        xAxis.setEnabled(false);  //是否打开x轴
    }

    private String famatTime(int value) {
        int min = value * 5;
        String m = min / 60 + "";
        if (min / 60 < 10) {
            m = "0" + min / 60;
        }
        String s = min % 60 + "";
        if (min % 60 < 10) {
            s = "0" + min % 60;
        }
        return m + ":" + s;
    }
    private int famatIndex(long value) {

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(value));

        int index =0;
        int start = ((calendar.get(Calendar.HOUR_OF_DAY)*60+calendar.get(Calendar.MINUTE))/5)-5;
        if(start>216){
            index = start - 216;
        }else {
            index = start+72;
        }
        Log.e("index",index+"");
        return index;
    }
}
